package com.micro.form;

import com.micro.utils.SeriaUtil;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

import java.io.IOException;

public class ImportForm extends Application {
    private static Stage stage1 = new Stage();

    static {
        try {
            Scene scene = new Scene(loadFXML("ImportForm"));
            stage1.setScene(scene);
            stage1.setTitle("M3u8Download");
            stage1.setOnCloseRequest((e) -> {
                SeriaUtil.writeData();
                System.exit(0);
            });
            stage1.setResizable(false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void hide() {
        stage1.hide();
    }

    public static void show() {
        stage1.show();
    }
    public static void onShow(EventHandler<WindowEvent> e){
        stage1.setOnShowing(e);
    }

    private static Parent loadFXML(String fxml) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(MainForm.class.getResource(fxml + ".fxml"));
        return fxmlLoader.load();
    }

    @Override
    public void start(Stage stage) throws IOException {
        stage = stage1;
        stage.show();
    }
}
